﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Animation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using System.Globalization;
using CrazyWorship1.PropertyHandler;

namespace CrazyWorship1.Transitions
{
    public class ZoomFadeIn : BaseTransitionIn
    {
        DoubleAnimation fade, zoom;
        public override void SetupTransition()
        {
            fade = new DoubleAnimation();
            fade.To = 1;
            fade.Duration = new Duration(new TimeSpan(0, 0, 0));

            zoom = new DoubleAnimation();
            zoom.From = 3;
            zoom.To = 0;
            zoom.Duration = new Duration(new TimeSpan(0, 0, 0));

         //   storyboard.Children.Add(fade);
         //   storyboard.Children.Add(zoom);
        }

        [DataAttribute("ZoomLength", typeof( IntPropertyHandler),"ZoomFadeInDefaultZoomLength")]
        public string ZoomLength
        {
            get
            {
                return zoom.Duration.TimeSpan.Seconds.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                zoom.Duration = new TimeSpan(0, 0, 0, Convert.ToInt32(value, CultureInfo.InvariantCulture), 0);
            }
        }

        [DataAttribute("FadeLength", typeof(IntPropertyHandler), "ZoomFadeInDefaultFadeLength")]
        public string FadeLength
        {
            get
            {
                return fade.Duration.TimeSpan.Seconds.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                fade.Duration = new TimeSpan(0, 0, 0, Convert.ToInt32(value, CultureInfo.InvariantCulture), 0);
            }
        }
        [DataAttribute("FadeTo", typeof( IntPropertyHandler),"ZoomFadeInDefaultFadeTo")]
        public string FadeTo
        {
            get
            {
                return fade.To.ToString();
            }
            set
            {
                fade.To = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }

        public override void Go()
        {

            //Storyboard.SetTargetProperty(storyboard.Children[0], new PropertyPath(TextBlock.OpacityProperty));
            //storyboard.Begin(textBlocks[CurrentState.CurrentLyric.LyricID]);
            //CurrentLyricTextBlock.BeginAnimation(TextBlock.OpacityProperty, fade);
            StartAnimation(CurrentLyricTextBlock, TextBlock.OpacityProperty, fade);

            TranslateTransform3D tf = new TranslateTransform3D();
            bool done=false;
            Transform3DCollection col = GetTransitionGroup(CurrentLyricTextPane,TransitionGroup.Transition).Children;
            foreach (TranslateTransform3D r in col){
                if (r != null)
                {
                    done=true;
                }
            }
            if (!done)    
            col.Add(tf);
            tf.BeginAnimation(TranslateTransform3D.OffsetZProperty, zoom);

        }
    }
}
